var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    address:''
  },
  setvalue(event){
    this.setData({
      address: event.detail.value
    });
  },
  baocunTap(){
    if (this.data.address.length > 0) {
      var that = this;
      app.AppHttp('api/Client/edit_address', {
        openid: app.globalData.openid,
        address: that.data.address
      }, function (res) {
        wx.showToast({
          title: res.data.msg
        }, 2000);
        if (res.data.status == 1) {
          app.globalData.loginInfo.address = that.data.address;
        }
        wx.navigateBack({
          url: '../../jibenshezhi'
        })
      });
    }else{
      wx.showLoading({
        title: '请输入地址',
        duration: 500
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      oldaddr: options.oldaddr
    })
  },
  getPermission(obj) {
    var that = this;
    wx.chooseLocation({
      success: function (res) {
        that.setData({
          address: res.name      //调用成功直接设置地址
        })
      },
      fail: function () {
        wx.getSetting({
          success: function (res) {
            var statu = res.authSetting;
            if (!statu['scope.userLocation']) {
              wx.showModal({
                title: '是否授权当前位置',
                content: '需要获取您的地理位置，请确认授权，否则地图功能将无法使用',
                success: function (tip) {
                  if (tip.confirm) {
                    wx.openSetting({
                      success: function (data) {
                        if (data.authSetting["scope.userLocation"] === true) {
                          wx.showToast({
                            title: '授权成功',
                            icon: 'success',
                            duration: 1000
                          })
                          //授权成功之后，再调用chooseLocation选择地方
                          wx.chooseLocation({
                            success: function (res) {
                              that.setData({
                                address: res.name
                              })
                            },
                          })
                        } else {
                          wx.showToast({
                            title: '授权失败',
                            icon: 'success',
                            duration: 1000
                          })
                        }
                      }
                    })
                  }
                }
              })
            }
          },
          fail: function (res) {
            wx.showToast({
              title: '调用授权窗口失败',
              icon: 'success',
              duration: 1000
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady(){

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow(){

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide(){

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload(){

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh(){
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})